package com.dongrj.framework.starter.sms;

import com.dongrj.framework.starter.sms.client.SmsClient;
import com.dongrj.framework.starter.sms.enums.SmsEnum;
import com.google.common.collect.Lists;

import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

public class DemoController {

    private SmsClient smsClient;

    @GetMapping("/hello")
    public String hello(Integer funcCode) {

        return "Hello";
    }


    public void sendCode(SmsEnum smsEnum, SmsSceneEnum smsSceneEnum, String mobile, String code) {
        List<SmsScene> smsScenes = allSmsScene();
        SmsScene smsScene = smsScenes.stream().filter(item -> item.findOne(smsEnum, smsSceneEnum)).findFirst().orElseThrow(() -> new IllegalArgumentException("未知场景!"));

        SmsRequest smsRequest = smsScene.buildRequest();
        smsRequest.setMobiles(mobile);
        smsRequest.addParam("code", code);
        SmsResponse send = smsClient.send(smsRequest);
    }


    public List<SmsScene> allSmsScene() {
        List<SmsScene> smsSceneList = Lists.newArrayListWithCapacity(4);
        smsSceneList.add(SmsScene.buildWithCode(SmsEnum.ALiYun, SmsSceneEnum.Login, "A001"));
        smsSceneList.add(SmsScene.buildWithCode(SmsEnum.ALiYun, SmsSceneEnum.Register, "A002"));

        smsSceneList.add(SmsScene.buildWithCode(SmsEnum.Tencent, SmsSceneEnum.Login, "T001"));
        smsSceneList.add(SmsScene.buildWithCode(SmsEnum.Tencent, SmsSceneEnum.Register, "T002"));

        smsSceneList.add(SmsScene.buildWithContent(SmsEnum.WeiDaoYun, SmsSceneEnum.Login, "欢迎登录"));
        smsSceneList.add(SmsScene.buildWithContent(SmsEnum.WeiDaoYun, SmsSceneEnum.Register, "欢迎注册"));
        return smsSceneList;
    }
}

